home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Tree View and List View / SysInfoListView / SysInfoListView.cs next >
Encoding:
Text File  |  2001-01-15  |  1.7 KB  |  55 lines

  1. //----------------------------------------------
  2. // SysInfoListView.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SysInfoListView: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new SysInfoListView());
  13.      }
  14.      public SysInfoListView()
  15.      {
  16.           Text = "System Information (List View)";
  17.  
  18.                // Create ListView control.
  19.  
  20.           ListView listview = new ListView();
  21.           listview.Parent = this;
  22.           listview.Dock = DockStyle.Fill;
  23.           listview.View = View.Details;
  24.           
  25.                // Define columns based on maximum string widths.
  26.  
  27.           Graphics grfx = CreateGraphics();
  28.  
  29.           listview.Columns.Add("Property", 
  30.                     (int) SysInfoReflectionStrings.MaxLabelWidth(grfx, Font),
  31.                     HorizontalAlignment.Left);
  32.  
  33.           listview.Columns.Add("Value",
  34.                     (int) SysInfoReflectionStrings.MaxValueWidth(grfx, Font),
  35.                     HorizontalAlignment.Left);
  36.  
  37.           grfx.Dispose();
  38.  
  39.                // Get the data that will be displayed.
  40.  
  41.           int      iNumItems  = SysInfoReflectionStrings.Count;
  42.           string[] astrLabels = SysInfoReflectionStrings.Labels;
  43.           string[] astrValues = SysInfoReflectionStrings.Values;
  44.  
  45.                // Define the items and subitems.
  46.  
  47.           for (int i = 0; i < iNumItems; i++)
  48.           {
  49.                ListViewItem lvi = new ListViewItem(astrLabels[i]);
  50.                lvi.SubItems.Add(astrValues[i]);
  51.                listview.Items.Add(lvi);
  52.           }
  53.      }
  54. }        
  55.